package com.aode.music.adapter.page;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.aode.music.view.fragment.chatfragment.FindFragment;
import com.aode.music.view.fragment.chatfragment.FriendFragment;
import com.aode.music.view.fragment.mefragment.CollectFragment;
import com.aode.music.view.fragment.mefragment.DownLoadFragment;

import java.util.HashMap;

public class MePagerAdapter extends FragmentPagerAdapter {
    private int num;
    private HashMap<Integer, Fragment> mFragmentHashMap = new HashMap<>();
    public MePagerAdapter(@NonNull FragmentManager fm, int num) {
        super(fm);
        this.num = num;
        Log.e("TAG",num+"");
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        return createFragment(position);
    }

    private Fragment createFragment(int position) {
        Fragment fragment = mFragmentHashMap.get(position);
        if(fragment==null){
            switch (position){
                case 0:
                    fragment = new CollectFragment();
                    break;
                case 1:
                    fragment = new DownLoadFragment();
                    break;
            }
            mFragmentHashMap.put(position,fragment);
        }

        return fragment;
    }

    @Override
    public int getCount() {
        return num;
    }
}
